package com.me.myFramework.aop22.aop120.intercept.method;

import org.springframework.aop.MethodBeforeAdvice;

/**
 * 《AOP-120》：  <br><br>
 *
 * 把切面逻辑抽取到单独接口中，后续通过组合模式调用 before()
 *
 * @author ME
 */
public class MethodBeforeAdviceInterceptor120 implements MethodInterceptor120 {

    private final MethodBeforeAdvice advice;

    public MethodBeforeAdviceInterceptor120(MethodBeforeAdvice advice) {
        this.advice = advice;
    }

    @Override
    public Object invoke(MethodInvocation120 mi) throws Throwable {
        this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis());

        return mi.getMethod().invoke(mi.getThis(), mi.getArguments());
    }

}
